class CounterS implements Runnable {

  private int counter = 0;
  private final int rounds = 100000;

  public void run () {
    try {
      int id;
      String name = Thread.currentThread().getName();
      if (name.equals("thread1")) id = 1;
      else id = 2;
      int tmp;
      for(int i = 0; i < rounds; i++) {
    	  if (id==1 && i==(rounds-1)) { Thread.sleep(8000); }
          if (id==0 && i==1) { Thread.sleep(3200); }
          tmp = counter;
          if (id==0 && i==0) { Thread.sleep(7200); }
          tmp++;
          if (id==1 && i==0) { Thread.sleep(800); }
          if (id==1 && i==(rounds-1)) { Thread.sleep(9600); }
          counter = tmp;
        // Or here?
      }
    } catch (InterruptedException e) {
      System.out.println ("Interrupted!");
    }
  }

  public static void main (String[] args) {
    try {
      CounterS c = new CounterS ();

      // Create two threads that run our run () method.
      Thread t1 = new Thread (c, "thread1");
      Thread t2 = new Thread (c, "thread2");

      t1.start (); t2.start ();

      // Wait for the threads to finish.
      t1.join (); t2.join ();

      // Print the counter
      System.out.println(c.counter);

    } catch (InterruptedException e) {
      System.out.println ("Interrupted!");
    }
  }

}